<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="renderer" content="webkit">
    <title>${setting.siteName} - 编辑轮播表</title>
    <meta name="keywords" content="${setting.siteName}">
    <meta name="description" content="${setting.siteName}">
    <!-- BEGIN HEADER -->
    [#include "/admin/include/style.ftl"]
    <style type="text/css">
        .imgPath {
            display: block;
        }

        .uploadBtn {
            top: 100px;
        }
    </style>

    <!-- END HEADER -->
</head>
<body class="gray-bg">
<div class="wrapper wrapper-content  animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>编辑轮播表</h5>
                    <div class="ibox-tools">
                        <button type="button" class="btn btn-outline btn-white btn-xs" id="btn-return-loippi"
                                onclick="location.href='${base}/admin/tcarousel/list.jhtml'"><i
                                    class="fa fa-reply-all"></i> 返回列表
                        </button>
                    </div>
                </div>
                <div class="ibox-content">
                    <form id="inputForm" class="form-horizontal" action="${base}/admin/tcarousel/update.jhtml"
                          method="post">
                        <input type="hidden" value="${tCarousel.id}" name="id"/>

                        <div class="form-group">
                            <div class="row">
                                <div class="col-sm-6">
                                    <label class="col-sm-3 control-label">是否删除</label>
                                    <div class="col-sm-9">
                                        [#--	                                    <input type="text" name="isDelete" class="form-control" maxlength="200" value="${(tCarousel.isDelete)!''}"/>--]
                                        <input type="radio" name="isDelete" value="0"/>否
                                        <input type="radio" name="isDelete" value="1"/>是
                                    </div>
                                </div>
                            </div>
                        </div>
                        <!--/row-->
                        <div class="form-group">
                            <div class="row">
                                <div class="col-sm-6">
                                    <label class="col-sm-3 control-label">图片名称</label>
                                    <div class="col-sm-9">
                                        <input type="text" name="name" class="form-control" maxlength="200"
                                               value="${(tCarousel.name)!''}"/>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="row">
                                <div class="col-sm-6">
                                    <label class="col-sm-3 control-label"><em
                                                style="color: red;">*&nbsp;</em>图片<br/></label>
                                    <div class="col-sm-9">
                                        <img style="width: 600px;height: 400px" id="imgPath" class="imgPath"
                                             src="${(tCarousel.img)!''}"/>
                                        <input type="file" name="file" class="form-control upload"
                                               onchange="change(this)" maxlength="200"/>
                                        <input type="button" class="btn btn-warning uploadBtn" style="margin-top:300px"
                                               value="修改"/>
                                        <input type="hidden" name="img" class="form-control imagePath" maxlength="200"/>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <!--/row-->
                        <div class="form-group">
                            <div class="row">
                                <div class="col-sm-6">
                                    <label class="col-sm-3 control-label">外部链接</label>
                                    <div class="col-sm-9">
                                        <input type="text" name="outUrl" class="form-control"
                                               value="${tCarousel.outUrl}" maxlength="200"/>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <div class="col-sm-12 col-sm-offset-10">
                                <button type="button" class="btn btn-default" onclick="window.history.back();">返回
                                </button>
                                <button class="btn btn-success" type="submit">保存内容</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<!-- BEGIN Script -->
[#include "/admin/include/script.ftl"]
<!-- END Script -->
<script>
    $(document).ready(function () {
        [@flash_message /]
        $(".chosen-select").chosen({width: "100%"});
        $(".input-daterange").datepicker({keyboardNavigation: false, forceParse: false, autoclose: true});

        $(".browserButton").browser({
            callback: function (url) {
                $("#" + $(this).attr('for')).val(url);
            }
        });

        $(".input-group.date").datepicker({
            todayBtn: "linked",
            keyboardNavigation: false,
            forceParse: false,
            calendarWeeks: true,
            autoclose: true
        });
        $("#inputForm").validate({
            rules: {
                name: {
                    required: true
                }
            },
            messages: {}
        });
    });

    // 上传
    function change(obj) {
        var that = obj;
        var formData = new FormData();
        var fileObj = $(obj)[0].files[0];
        formData.append("file", fileObj);
        $.ajax({
            url: '${base}/admin/file/upload.jhtml',
            type: 'POST',
            data: formData,
            dataType: "json",
            async: false,
            processData: false,
            contentType: false,
            success: function (data) {
                $(that).parent().find(".imgPath").show();
                $(that).parent().find(".imgPath").attr("src", data.url);
                $(that).parent().find(".uploadBtn").css({"top": "100px"});
                $(that).parent().find(".imagePath").val(data.url);
                $(that).parent().find(".uploadBtn").val("修改");
            }
        })
    }

    // 根据后台返回值，选中单选框
    var isDeletes = document.getElementsByName("isDelete");
    for (var i = 0; i < isDeletes.length; i++) {
        if (isDeletes[i].value == ${tCarousel.isDelete}) {
            isDeletes[i].checked = 'checked';
        }
    }
</script>
</body>
</html>
